import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JScrollBar;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * This class is StudentUI
 */
public class StudentUI extends JPanel {

	/**
	 * StudentUI variables
	 */
	private JLabel stltitle = null;
	private JButton btnRecSubAss = null;
	private JButton btnOpenChkAss = null;
	private JButton btnGetInfo = null;
	public JButton btnHelp = null;
	public JButton btnLogout = null;
	private JPanel curPanel;
	private String ID;
	
	/**
	 * @param id
	 */
	public StudentUI (String id) {
		super();
		ID = id;
		initialize();	
	}
	/**
	* Init all the Variables
	*/
	private void initialize() {
		curPanel = this;
		btnRecSubAss = new JButton();
		btnRecSubAss.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SQL s = new SQL(Global.logIn.getUserlogin(),16);
				s.accept();
				//System.out.println("TEMP NSG   " + Global.chat.temp);
				ReceiveAssignmentUI ReceiveAssignmentUI;
				Object msg = s.getMsg();
				if (msg.equals("NoAssignment")) // No Assignments
				{
					ReceiveAssignmentUI = new ReceiveAssignmentUI();
				}
				else // Receive assignment courses
				{
					System.out.println("Receive Assignment Return Courses " + msg.toString());	
					ReceiveAssignmentUI = new ReceiveAssignmentUI(msg);
				}
				setVisible(false);
				System.out.println("Receive/Submit Assignment");
				Global.main.setContentPane(ReceiveAssignmentUI);
				ReceiveAssignmentUI.btnBack.addActionListener(new ActionListener() {   //back from ReceiveAssignmentUI
					public void actionPerformed(ActionEvent arg0) {
						Global.main.setContentPane(curPanel);
						curPanel.setVisible(true);
					}
				});
				
				
			}
		});
		btnRecSubAss.setBounds(new Rectangle(130, 100, 200, 25));
		btnRecSubAss.setText("Recive/Submit Assinment");
		this.add(btnRecSubAss,null);
		this.setVisible(true);
		

		/**
		 *  Open Check Assignment button Implementation
		 */
		btnOpenChkAss = new JButton();
		btnOpenChkAss.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SQL s = new SQL(Global.logIn.getUserlogin(),52);
				s.accept();
				OpenCheckedAssUI OpenCheckedAssUI;
				Object msg = s.getMsg();
				if (msg.equals("NoAssignment")) // No Assignments
				{
					OpenCheckedAssUI = new OpenCheckedAssUI();
				}
				else // Receive assignment courses
				{
					System.out.println("Receive Assignment Return Courses " + msg.toString());	
					OpenCheckedAssUI = new OpenCheckedAssUI(msg);
				}
				setVisible(false);
				System.out.println("Open Checked Assignment");
				Global.main.setContentPane(OpenCheckedAssUI);
				OpenCheckedAssUI.btnBack.addActionListener(new ActionListener() {   //back from ReceiveAssignmentUI
					public void actionPerformed(ActionEvent arg0) {
						Global.main.setContentPane(curPanel);
						curPanel.setVisible(true);
					}
				});
				
				
			}
		});
		btnOpenChkAss.setBounds(new Rectangle(130, 155, 200, 25));
		btnOpenChkAss.setText("Open Checked Assinment");
		this.add(btnOpenChkAss,null);
		this.setVisible(true);
		
		/**
		 *  GetInfo button Implementation
		 */
		btnGetInfo = new JButton();
		btnGetInfo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("Get Info");
				Student s = new Student(ID);
				s.DBSHOW();
			}
		});
		btnGetInfo.setBounds(new Rectangle(130, 210, 200, 25));
		btnGetInfo.setText("Get Info");
		this.add(btnGetInfo,null);
		this.setVisible(true);

		stltitle = new JLabel("Student Log In");
		stltitle.setBounds(193, 28, 110, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(stltitle);

		this.setVisible(true);
		
		/**
		 *  Help button Implementation
		 */
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Choose one of the options");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
		/**
		 *  Logout button Implementation
		 */
		btnLogout = new JButton("Logout");        //Logout button
		btnLogout.setBounds(10, 11, 80, 19);
		add(btnLogout);
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  LogoutWin logt = new LogoutWin();
				  System.out.println("user press Logout button");
			}
		});
		this.setVisible(true);
		
	}			
}

